<?php
	/* * *
 	* This file must contain the full set of functions that can be called from the template index.php
 	* page.
 	*/

	class C_tools {
		const PAGE_NAME = "##PAGE_NAME##";
		var $classe;
		var $secPlugin;
	
		const main_sec = "##MAIN_SEC##";
		const top_sec = "##TOP_SEC##";
		const side_sec = "##SIDE_SEC##";
		const header_sec = "##HEAD_SEC##";
	
		function C_tools(&$mainClass) {
			$this->classe = $mainClass;
		}
		
		function setSecPlugin(&$secPlugin) {
			$this->secPlugin = $secPlugin;
		}
		
		function redirect($url,$tempo = FALSE ){
 			if(!headers_sent() && $tempo == FALSE ){
  				header('Location:' . $url);
 			}elseif(!headers_sent()){
  				header('Refresh:' . $tempo . ';' . $url);
 			}else{
  				if($tempo == FALSE ){
    				$tempo = 0;
  				}
  				echo "<meta http-equiv=\"refresh\" content=\"" . $tempo . ";" . $url . "\">";
  			}
		}
		function loadLoginArea() {
			$this->secPlugin->secPrintLoginModule();
		}
		function loadRegisterArea() {
			$this->secPlugin->secPrintRegisterModule();
		}
	
		function loadModule($modName) {
			$fullPath = "metas/modules/". $modName. "/mod.php";
			if (!file_exists($fullPath)) 
				die('invalid request');
			include $fullPath; 
			$mod->setToolKit($this);
			$mod->setSec($this->secPlugin);
			if (!$mod->needsAuthentication() || $this->classe->isRegistered) {
				$mod->getContent();
			}
		}
		
		function loadModules($mod_section, $mode) {
			include_once 'logic.php';
			$a = $this->classe;
			$tempName = "metas/templates/". $a->templateName. "/mod.php";
			for ($i = 1; $i <= $a->modCount; $i++) {
				$fullPath = "metas/modules/". $a->moduleList->readNode($i). "/mod.php";
				$pos = $a->posList->readNode($i);
				if ($pos == $mod_section) {
					include $fullPath;
					$mod->setToolKit($this);
					$mod->setSec($this->secPlugin);
					if (!$mod->needsAuthentication() || $this->classe->isRegistered) {
						include $tempName;
					}
				}
			}
		}
				
		function getTemplateURL() {
			return 'metas/templates/' . $this->classe->templateName;
		}
		
		function getMediaURL() {
			return 'metas/media/';
		}
		
		function getGet($name) {
			$retval = "";
			
			if (strcmp($name, C_Tools::PAGE_NAME)==0) {
				$retval = $_SERVER['PHP_SELF'];
				return $retval;
			}
		
			if (isset($_GET[$name])) {
				$retval = $_GET[$name];
				return $retval;
			} 
			return "";
		}
		
		function getPost($name) {
			$retval = "";
			
			if (strcmp($name, C_Tools::PAGE_NAME)==0) {
				$retval = $_SERVER['PHP_SELF'];
				return $retval;
			}
		
			if (isset($_POST[$name])) {
				$retval = $_POST[$name];
				return $retval;
			} 
			return "";
		}
	
		function pageName() {
			return $this->getget(C_Tools::PAGE_NAME);
		}
		
		function isLogged() {
			return $this->classe->isRegistered;
		}
		
		function getLoginURL() {
			return $this->pageName() . "?showlogin=1";
		}
		
		function getRegisterURL() {
			return $this->pageName() . "?register=1";
		}
	}
?>